const KoaRouter = require('koa-router');
const router = new KoaRouter();
const { Group } = require('../database/index')

router.prefix('/group');

router.
  post('/create', async ctx =>{
    let { groupName,imagePath,folders,members,setTime,creater,username} = ctx.request.body
    let group =  new Group({
      groupName,
      imagePath,
      folders,
      members,
      setTime,
      creater,
      username
    })

    await group.save();

    ctx.response.body={
      msg: '新建组'+groupName,
      code: 20000
    }
  })
  .post('/getList', async ctx => {
    let { username } = ctx.request.body
    let groupList = await Group.find({
      username
    })

    ctx.response.body = {
      groupList,
      code: 20000
    }
  })

  module.exports.groupRouter = router